<?php

namespace app\admin\model\notice;

use think\Db;
use think\Model;
use think\Queue;


class Admin extends Model
{
    // 表名
    protected $name = 'notice_admin';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    protected static function init()
    {
        self::afterInsert(function ($row) {
            //系统通知每个用户
            $users = Db::name('user')->column('id');
            foreach ($users as $v){
                Db::name('notice')->insert([
                    'user_id' =>$v,
                    'title' => $row['title'],
                    'content' => $row['content'],
                    'type' => 2,
                    'createtime' => time(),
                    'updatetime' => time()
                ]);
            }
        });
    }

}
